#include "Super_Widget.h"
#include "Super_Man.h"

Super_Widget::Super_Widget(Super_Man* hero, const vec2f& s) : size(s), myHero(hero) {
	SetColor(sf::Color(127,127,127,127));
}
Super_Widget::~Super_Widget() {}

void Super_Widget::SetSize(const vec2f& s){
	size=s;
	updateRect();
}
void Super_Widget::AddSize(const vec2f& s){
	size+=s;
	updateRect();
}
void Super_Widget::SetPosition(float X, float Y){
	sf::Drawable::SetPosition(X, Y);
	updateRect();
}
void Super_Widget::SetPosition(const sf::Vector2f& Position){
	sf::Drawable::SetPosition(Position);
	updateRect();
}
void Super_Widget::SetX(float X){
	sf::Drawable::SetX(X);
	updateRect();
}
void Super_Widget::SetY(float Y){
	sf::Drawable::SetY(Y);
	updateRect();
}
void Super_Widget::Move(float OffsetX, float OffsetY){
	sf::Drawable::Move(OffsetX, OffsetY);
	updateRect();
}
void Super_Widget::Move(const sf::Vector2f& Offset){
	sf::Drawable::Move(Offset);
	updateRect();
}
void Super_Widget::Rotate(float Angle){/*no rotating!*/}
vec2f Super_Widget::GetSize() const{return size;}
sf::FloatRect Super_Widget::GetRect() const{return myRect;}
void Super_Widget::update(const sf::Input& sfi, float time){
	if(IsInside(sfi.GetMouseX(), sfi.GetMouseY()))
		SetColor(sf::Color(127,0,0,127));
	else
		SetColor(sf::Color(127,127,127,127));
}
void Super_Widget::Render(sf::RenderTarget& Target) const{
	glDisable(GL_TEXTURE_2D);
	glBegin(GL_QUADS);
	glVertex2f(0.f,0.f);
	glVertex2f(size.x, 0.f);
	glVertex2f(size.x, size.y);
	glVertex2f(0.f, size.y);
	glEnd();
}
void Super_Widget::reAssign(Super_Man* hero) {myHero=hero;}
bool Super_Widget::IsInside(const vec2f& Position) const{
	return this->IsInside(Position.x, Position.y);
}
bool Super_Widget::IsInside(const sf::Vector2f& Position) const{
	return this->IsInside(Position.x, Position.y);
}
bool Super_Widget::IsInside(float x, float y) const{
		bool outside;
	outside = x < myRect.Left ||
			x > myRect.Right ||
			y < myRect.Top ||
			y > myRect.Bottom;
	return !outside;
}
void Super_Widget::updateRect(){
	myRect.Left=GetPosition().x;
	myRect.Top=GetPosition().y;
	myRect.Right=GetPosition().x+size.x;
	myRect.Bottom=GetPosition().y+size.y;
}

Text_Widget::Text_Widget(Super_Man* hero, const sf::Unicode::Text& text) : Super_Widget(hero){
	SetText(text);
}
void Text_Widget::SetText(const sf::Unicode::Text& text){
	myText.SetText(text);
	sf::FloatRect rect = myText.GetRect();
	SetPosition(rect.Left, rect.Top);
	SetSize(vec2f(rect.Right-rect.Left, rect.Bottom-rect.Top));
}
const sf::Unicode::Text& Text_Widget::GetText() const{
	return myText.GetText();
}
void Text_Widget::SetFonts(){
	myText.SetFont(myHero->GetFont());
	myText.SetSize(myHero->GetFont().GetCharacterSize());
}
void Text_Widget::Render(sf::RenderTarget& Target) const{
	Super_Widget::Render(Target);
	Target.Draw(myText);
}






